package com.zc.controller.demo;

import com.zc.domain.po.Demo;
import com.zc.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by zhangchi9 on 2016/11/10.
 */
@Controller
@RequestMapping("/demo")
public class HelloWorldController {

    @Value("${jdbc_name}")
    private String str;

    @Autowired
    Environment environment;

    @Autowired
    private DemoService demoService;


    @RequestMapping(value="/helloWorld.action",method = RequestMethod.GET)
    public String helloWorld(@RequestParam("id") String id, Model model){
        System.out.println("The Spring MVC HelloWorld Demo!");
        System.out.println(str);
        System.out.println(environment.getProperty("jdbc_password"));
        model.addAttribute("en", environment.getProperty("jdbc_password"));
        model.addAttribute("str",str);
        model.addAttribute("id",id);

        Demo demo = new Demo();
        demo.setName("汉字");
        demo.setStpositionValue(new Float(2));
        demo.setStpositionRule(3);
        demoService.gainDemo(demo);

        return "/hello";
    }
}
